export const findValueWith = (number, arr = []) => {
    arr = arr.sort((a, b) => a.value - b.value)
    let result = '优'
    for (const key in arr) {
      if (parseFloat(number) < parseFloat(arr[key].value)) {
        result = arr[key].label
        break
      }
    }
  
    return result
  }
  
  export const getQualityByValue = (value, name) => {
    name = name?.toLocaleUpperCase()
    switch (name) {
      case 'TVOC':
        return findValueWith(value, [
          { value: 0.3, label: '优' },
          { value: 0.5, label: '中' },
          { value: 999, label: '差' },
        ])
      case 'CO2':
        return findValueWith(value, [
          { value: 800, label: '优' },
          { value: 1000, label: '中' },
          { value: 9999, label: '差' },
        ])
      case 'PM25':
        return findValueWith(value, [
          { value: 35, label: '优' },
          { value: 75, label: '良' },
          { value: 9999, label: '差' },
        ])
      case 'CAS':
        return findValueWith(value, [
          { value: 0.03, label: '优' },
          { value: 0.08, label: '中' },
          { value: 9999, label: '差' },
        ])
      case 'TEMP':
        break
      case 'HUMI':
        break
      case 'QUALITY':
        return findValueWith(value, [
          { value: 50, label: '优' },
          { value: 100, label: '中' },
          { value: 9999, label: '差' },
        ])
    }
  }

  export const getTextColor = (str = '优') =>{
    const classMap = {
      优: '#48bb78',
      良: '#ecc94b',
      中: '#ecc94b',
      差: '#f56565',
      轻度污染: '#ecc94b',
      中度污染: '#ecc94b',
      重度污染: '#f56565',
      严重污染: '#f56565',
      高: '#f56565',
    }
    return classMap[str]
  }
  